package ar.com.temporis.system.service;

import ar.com.temporis.framework.domain.DomainException;
import ar.com.temporis.system.domain.User;
import ar.com.temporis.system.persistence.UserRepository;

/**
 * 
 * @author matias.sulik
 * 
 */
public class LoginServiceImpl implements LoginService {

	private UserRepository userRepository;

	public User autenticate(String username, String password) {
		try {
			User user = this.userRepository.findUserBy(username, password);
			
			if (user == null) {
				throw new Exception();
			}
			
			return user;
		} catch (Exception e) {
			throw new DomainException("The user is incorrect.");
		}
	}

	public UserRepository getUserRepository() {
		return userRepository;
	}

	public void setUserRepository(UserRepository userRepository) {
		this.userRepository = userRepository;
	}

}
